int w = 800;
int h = 600;
color backgroundColor = color(255, 255, 255);
color pointsColor = color(255, 0 ,0);
ArrayList<PVector> points = new ArrayList<PVector>();
Button splineButton;


void setup() {
  size(w, h);
  background(backgroundColor);
  PImage icon = loadImage("icons/default.jpg");
  PImage overIcon = loadImage("icons/pressed-default.jpg");
  splineButton = new Button(icon, overIcon, 0, 0, 40);
}

void draw() {
  if(splineButton.isInside(mouseX, mouseY)) {
    splineButton.drawButton(true);
  }
  else {
    splineButton.drawButton(false);
  }
}

void mouseClicked() {
  
  int x = mouseX;
  int y = mouseY;
  
  if(!splineButton.isInside(x,y)) {
    //Add point to the ArrayList
    PVector point = new PVector();
    point.x = x;
    point.y = y;
    points.add(point);
    stroke(pointsColor);
    //Draw point
    fill(pointsColor);
    ellipse(x, y, 3, 3);
  }
  else{
    //Se debe hacer el spline con los puntos actuales.
    NaturalSpline naturalSpline = new NaturalSpline(points);
    naturalSpline.run();
  }
  
  /*println("----------------");
  for(PVector p : points) {
    println("x " + p.x + " , y "+p.y);
  }*/
}
